#include <bits/stdc++.h>

#define N 25000

using namespace std;

int dp[N] = {0};
int tim[N];
int ans = 0;

int main(){
    int a[5];
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    int n;  //科目
    for(n = 1; n <= 4; n++){
        int sum = 0;
        for(int i = 1; i <= a[n]; i++){
            cin >> tim[i];
            sum += tim[i];
        }
        dp[0] = 1;
        if(a[n] == 1){
            ans += tim[1];
            continue;
        }
        for(int i = 1; i <= a[n]; i++){
            for(int j = sum/2 + 1; j >= tim[i]; j--){
                if(dp[j - tim[i]]){
                    dp[j] = 1;
                }
            }
        }
        for(int j = sum/2 + 1; j >= 0; j--){
            if(dp[j]){
                cout << j << " ";
                ans += j;
                break;
            }
        }
        cout << ans << endl;
        memset(dp, 0, sizeof(dp));
    }
    cout << ans << endl;
    return 0;
}